﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ActiveWeaponContainer.cs" company="">
//   
// </copyright>
// <summary>
//   TODO: Update summary.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

/*
 * Author: Juan Mompean Esteban
 * Created: 28-11-2011 
 */
namespace ITU_vs_Zombies.Graphics
{
    using System;
    using System.Diagnostics.Contracts;

    using ITU_vs_Zombies.Game;
    using ITU_vs_Zombies.Stuff;

    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;

    /// <summary>
    /// Show the active weapon of the player.
    /// </summary>
    public class ActiveWeaponContainer
    {
        #region Constants and Fields

        /// <summary>
        /// The animation.
        /// </summary>
        private readonly Animation animation;

        /// <summary>
        /// The screen width.
        /// </summary>
        private int screenWidth;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ActiveWeaponContainer"/> class.
        /// </summary>
        public ActiveWeaponContainer()
        {
            this.animation = new Animation();
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets ExtraObject.
        /// </summary>
        public ExtraObject ExtraObject { get; set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// The dispose.
        /// </summary>
        public void Dispose()
        {
            this.animation.Dispose();
        }

        /// <summary>
        /// The draw.
        /// </summary>
        /// <param name="spriteBatch">
        /// The sprite batch.
        /// </param>
        public void Draw(SpriteBatch spriteBatch)
        {
            Contract.Requires(spriteBatch != null);
            this.animation.Draw(spriteBatch);
            this.ExtraObject.Draw(spriteBatch);
        }

        /// <summary>
        /// The initialize.
        /// </summary>
        /// <param name="screenWidth">
        /// The screen width.
        /// </param>
        public void Initialize(int screenWidth)
        {
            Contract.Requires(screenWidth > 0);
            this.screenWidth = screenWidth;
        }

        /// <summary>
        /// The load content.
        /// </summary>
        public void LoadContent()
        {
            Contract.Requires(Client.Content != null);
            var texture = Client.Content.Load<Texture2D>(@"activeWeapon");
            this.animation.Initialize(texture, new Vector2(), 1, Color.White, 1f, true, false);
        }

        /// <summary>
        /// The update.
        /// </summary>
        /// <param name="gameTime">
        /// The game time.
        /// </param>
        /// <param name="floorPosition">
        /// The floor position.
        /// </param>
        /// <param name="extraObject">
        /// The extra object.
        /// </param>
        public void Update(GameTime gameTime, Vector2 floorPosition, ExtraObject extraObject)
        {
            Contract.Requires(gameTime != null);
            Contract.Requires(extraObject != null);
            this.animation.Position = new Vector2(this.screenWidth / 2, 10);
            this.animation.Update(gameTime);
            this.ExtraObject = extraObject;
            this.ExtraObject.Position =
                new Vector2(
                    Math.Abs(floorPosition.X) + this.animation.Position.X + (int)(this.animation.FrameWidth * 0.2), 
                    this.animation.Position.Y + (int)(this.animation.FrameHeight * 0.2));
            this.ExtraObject.Animation.Resize(this.animation.FrameWidth * 0.6, this.animation.FrameHeight * 0.6);

            this.ExtraObject.Update(gameTime, floorPosition);
        }

        #endregion
    }
}